package net.techwatch.jpa.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

@Entity
@NamedQueries( {
		@NamedQuery(name = "getPersonByLastName", query = "SELECT e FROM Person as e WHERE lastName= :name"),
		@NamedQuery(name = "getPersonByPhoneNumber", query = "SELECT e FROM Person as e WHERE phoneNumber= :phone") })
@Inheritance(strategy = InheritanceType.JOINED)
@EntityListeners(LifeCycleMonitor.class)
public class Person implements Serializable {

	private static final long serialVersionUID = 3484269708438876070L;
	
	private long id;
	private String firstName;
	private String lastName;
	private String phoneNumber;
	private Address address;

	public Person() {
		// nothing to do
	}

	/**
	 * @return the id
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PERSON_ID", nullable = false)
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	@SuppressWarnings("unused")
	private void setId(long id) {
		this.id = id;
	}

	/**
	 * @return the firstName
	 */
	@Column(name = "FIRST_NAME", nullable = false)
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	@Column(name = "LAST_NAME", nullable = false)
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the fullName
	 */
	@Transient
	public String getFullName() {
		return firstName + " " + lastName;
	}

	/**
	 * @param fullName
	 *            the fullName to set
	 */
	@SuppressWarnings("unused")
	private void setFullName(String fullName) {
		// nothing to do
	}

	/**
	 * @return the phoneNumber
	 */
	@Column(name = "PHONE_NO", nullable = false)
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param phoneNumber
	 *            the phoneNumber to set
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	/**
	 * @return the address
	 */
	@Embedded
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address
	 *            the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

}
